package com.tiny.mirror.service.product.application.command;

import com.api.tiny.mirror.service.product.request.CreateAbilityRequest;
import com.api.tiny.mirror.service.product.request.UpdateAbilityRequest;
import com.tiny.mirror.service.product.application.convert.AbilityConvert;
import com.tiny.mirror.service.product.domain.ability.Ability;
import com.tiny.mirror.service.product.domain.ability.service.AbilityDomainService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: liujsh
 * @Description:
 * @Date: Create in 2023/9/27
 */
@Service
public class AbilityCmdService {

  @Resource
  private AbilityDomainService abilityDomainService;

  @Transactional
  public Long create(CreateAbilityRequest request) {
    Ability app = AbilityConvert.convertToAbility(request);
    return abilityDomainService.create(app);
  }

  @Transactional
  public void update(UpdateAbilityRequest request) {
    Ability app = AbilityConvert.convertToAbility(request);
    abilityDomainService.update(request.getId(), app);
  }

  @Transactional
  public Integer delete(List<Long> ids) {
    int result = 0;
    for (Long id : ids) {
      abilityDomainService.delete(id);
      result++;
    }
    return result;
  }
}
